package com.alipear.uibase;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;

/**
 * Created by zoulinlin on 2015/4/2.
 */
public class ImageLoadWrapper  {

    DisplayImageOptions options;
    private ImageLoader mImageLoader;

    public ImageLoadWrapper(Context c) {
        mImageLoader = ImageLoader.getInstance();
        mImageLoader.init(ImageLoaderConfiguration.createDefault(c));
    }

    @SuppressWarnings("deprecation")
    public void bindImage(ImageView view, String url, Drawable defaultImage) {
        options = new DisplayImageOptions.Builder()
		/*
		 * .showStubImage(R.drawable.ic_stub)
		 * .showImageForEmptyUri(R.drawable.ic_empty)
		 * .showImageOnFail(R.drawable.ic_error)
		 */
                .cacheInMemory().cacheOnDisc()
                        // .displayer(new RoundedBitmapDisplayer(20))
                .build();

        mImageLoader.displayImage(url, view, options);
    }

    @SuppressWarnings("deprecation")
    public void bindImage(ImageView view, String url, Drawable defaultImage,
                          ImageLoadingListener listener) {
        options = new DisplayImageOptions.Builder()
		/*
		 * .showStubImage(R.drawable.ic_stub)
		 * .showImageForEmptyUri(R.drawable.ic_empty)
		 * .showImageOnFail(R.drawable.ic_error)
		 */
                .cacheInMemory().cacheOnDisc()
                        // .displayer(new RoundedBitmapDisplayer(20))
                .build();

        mImageLoader.displayImage(url, view, options, listener);
    }

}

